<template>
	<view>
		<view class="content">
			<text class="iconfont" style="color: #e64340;">&#xe8ce;</text>论文数：{{info.paperNumber}}
		</view>
		<view class="content">
			<text class="iconfont" style="color: #c60ce6;">&#xe62e;</text>专著数：{{info.treatiseNumber}}
		</view>
		<view class="content">
			<text class="iconfont" style="color: #f8ea24;">&#xe7fc;</text>获奖数：{{info.awardNumber}}
		</view>
		<view class="content">
			<text class="iconfont" style="color: #47e6c7;">&#xe660;</text>专利数：{{info.patentNumber}}
		</view>
		<view class="content">
			<text class="iconfont" style="color: #5f47e6;">&#xe6eb;</text>国家项目数： {{info.countryProjectNumber}}
		</view>
		<view class="content">
			<text class="iconfont" style="color: #aaaaff;">&#xe6eb;</text>国家立项数：{{info.countryProjectLeaderNumber}}
		</view>
		<view class="content">
			<text class="iconfont" style="color: #e6c896;">&#xe6eb;</text>省部项目数：{{info.provinceProjectNumber}}
		</view>
		<view class="content">
			<text class="iconfont" style="color: #56e660;">&#xe6eb;</text>省部立项数：{{info.provinceProjectLeaderNumber}}
		</view>
		<view class="content">
			<text class="iconfont" style="color: #e614d5;">&#xe62f;</text>招生专业：{{info.major}}</view>
		<view class="footer">
			<button type="warn" @click="reApply">
				<text class="iconfont">&#xe76d;</text>重新申请
			</button>
		</view>
	</view>
</template>
<script>
	import {
		recruitInfo,
		recruitApply,
		recruitReApply,
	} from '@/api/tRecruit.js'

	function timeFormat() {
		const date = new Date()
		let year = date.getFullYear()
		let month = date.getMonth() + 1
		let day = date.getDate()
		let hour = date.getHours()
		let min = date.getMinutes()
		let second = date.getSeconds()
		month = month > 9 ? month : '0' + month
		day = day > 9 ? day : '0' + day;
		hour = hour > 9 ? hour : '0' + hour;
		min = min > 9 ? min : '0' + min;
		second = second > 9 ? second : '0' + second;
		return `${year}-${month}-${day} ${hour}:${min}:${second}`
	}
	export default {
		data() {
			return {
				info: {
					teaRecruitId: '',
					tid: '',
					paperNumber: 0,
					treatiseNumber: 0,
					projectNumber: 0,
					awardNumber: 0,
					patentNumber: 0,
					countryProjectNumber: 0,
					countryProjectLeaderNumber: 0,
					provinceProjectNumber: 0,
					provinceProjectLeaderNumber: 0,
					major: '',
				}
			}
		},
		methods: {
			reApply() {
				recruitReApply({
					tid: getApp().globalData.tid,
					time: timeFormat(),
					type: 1,
					apply: 0,
					past: 0,
					teaRecruitId: this.info.teaRecruitId,
				}).then(res => {
					if (res.data.code == 0) {
						uni.showModal({
							content: '已申请，等待审核',
						})
					}
				}).catch(err => {
					uni.showModal({
						content: '申请失败'
					})
				})
			},
			getData(){
				uni.showLoading()
				//获得数据
				recruitInfo({
					tid: getApp().globalData.tid
				}).then(res => {
					// console.log(res)
					if (!res.data.data) {
						uni.hideLoading()
						uni.showModal({
							content: '您尚未申请或申请未通过',
							confirmText: '申请',
							success(res) {
								if (res.confirm) {
									recruitApply({
										tid: getApp().globalData.tid,
										type: 0,
										apply: 0,
										past: 0,
										time: timeFormat()
									}).then(res => {
										if (res.data.code == 0) {
											uni.showModal({
												content: '已申请，等待审核',
												complete() {
													uni.navigateBack()
												}
											})
										}
									}).catch(err => {
										uni.showModal({
											content: '申请失败'
										})
									})
								} else {
									uni.navigateBack()
								}
							}
						})
					} else {
						this.info = res.data.data
						uni.hideLoading()
					}
				}).catch(err => {
					uni.hideLoading()
					uni.showModal({
						content: '请求失败'
					})
				})
			}
		},
		onLoad() {
			this.getData()
		}
	}
</script>

<style>
	page {
		background-color: #f9f9f9;
		font-family: 'Courier New', Courier, monospace;
	}

	.content {
		padding: 15px;
		font-size: 16px;
		line-height: 20px;
		color: #666;
		border-bottom: 1px dotted #C0C0C0;
		margin: 5px 8px;
		box-shadow: 2px 2px 1px #cedce2;
	}

	.iconfont {
		font-family: "iconfont" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		margin-right: 5px;
	}
	.footer{
		margin: 10px;
	}
</style>
